package com.hzmall.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzmall.common.ServerResponse;
import com.hzmall.dao.ProductMapper;
import com.hzmall.pojo.Product;
import com.hzmall.service.impl.ProductService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/product/")
public class ProductController {
    @Autowired
    private ProductService productService;

    //产品搜索及动态排序
    @RequestMapping(value = "list.do")
    @ResponseBody
    public ServerResponse list(Integer categoryId, String keyword,
                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                               @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                               @RequestParam(value = "orderBy",defaultValue = "") String orderBy){
        return this.productService.list(categoryId, keyword, pageNum, pageSize, orderBy);
    }

    //产品详情
    @RequestMapping(value = "detail.do")
    @ResponseBody
    public ServerResponse detail(Integer productId){
        return this.productService.detail(productId);
    }
}
